package com.example.emqx.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.emqx.entity.ApiResponse;
import com.example.emqx.entity.DevicesEmqAll;
import com.example.emqx.service.DevicesEmqAllService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DevicesEmqAllController {
    @Autowired
    private DevicesEmqAllService devicesAllEmqService;

    @GetMapping("/list/all")
    public ApiResponse<List<DevicesEmqAll>> listUsers() {
        return ApiResponse.success(devicesAllEmqService.list());
    }

    @GetMapping("/list")
    public ApiResponse<Page<DevicesEmqAll>> listDevices(@RequestParam(defaultValue = "1") int page,
                                           @RequestParam(defaultValue = "10") int size) {
        Page<DevicesEmqAll> devicesPage = new Page<>(page, size);
        // 使用分页查询
        devicesAllEmqService.page(devicesPage, new QueryWrapper<DevicesEmqAll>());
        return ApiResponse.success(devicesPage);
    }
}
